// components/hot_goods/hot_goods.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    listData: [],
    imgPath: "/images"
  },

  /**
   * 组件的方法列表
   */
  methods: {
    detail(e){
     //console.log("eeeeee",e)
      wx.navigateTo({
        url: '/pages/goods/detail?goods_id='+e.currentTarget.dataset.goods_id,
      })
    }
  },
  lifetimes: {
    attached() {
      let that=this;

      const util = require("../../utils/util")

      //图片路径
      this.setData({
        imgPath: util.getImgPath()
      })
      // console.log("hot_goods,this.data.imgPath", this.data.imgPath)

      //取得商品列表
      this.setData({
        listData: []
      })
      const api = require("../../api/api");
      api.goods.list({
        page: "1",
        goods_type: '200',
        success(res) {
          // console.log("hot_goods,list,res", res)
          let rows = res.data.data.rows;
          for (const row of rows) {
            that.data.listData.push({
              imgsrc: row.image,
              content: row.goods_name,
              price: row.price,
              goods_id:row.goods_id,
              original_price:row.original_price
            })
          }

          //刷新数据
          that.setData({
            listData: that.data.listData,
          })
        }
      })

      // //商品列表
      // this.data.listData.push({
      //   imgSrc: this.data.imgPath + '/home/goods1.png',
      //   content: 'MAGIC DRAGON魔杰龙轻柔倍适纸尿裤'
      // })
      // this.data.listData.push({
      //   imgSrc: this.data.imgPath + '/home/goods1.png',
      //   content: 'MAGIC DRAGON魔杰龙轻柔倍适纸尿裤'
      // })

    }
  }
})